//index.js
//获取应用实例
const app = getApp()
import { axios } from '../../request/myAxios';
Page({
  data: {
    swiperList: [],
    navList: [],
    floorsList: [],
    showtop: false,
    finishLoading: false
  },
  onLoad() {
    // wx.request({
    //   url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
    //   method: 'GET',
    //   dataType: 'json',
    //   success: (result) => {
    //     console.log("结果", result)
    //     this.setData({
    //       swiperList: result.data.message
    //     })
    //   },
    //   fail: () => { },
    //   complete: () => { }
    // });
    // 封装后的写法
    const p1 = axios({
      url: "/home/swiperdata"
    }).then(res => {
      // console.log("结果", res);
      this.setData({
        swiperList: res
      })
    })
    //快捷导航
    const p2 = axios({
      url: "/home/catitems"
    }).then(res => {
      console.log("导航", res);
      this.setData({
        navList: res
      })
    })
    // 商品楼层
    const p3 = axios({
      url: '/home/floordata'
    }).then(res => {
      console.log("楼层", res);
      this.setData({
        floorsList: res
      })
    })

    Promise.all([p1, p2, p3]).then(res => {
      wx.stopPullDownRefresh()  //停止当前页面的下拉刷新
      //数据更新完毕，loading隐藏
      this.setData({
        finishLoading: true
      })
    })



  },
  getJumptopage(e) {
    let { url, type } = e.currentTarget.dataset;
    console.log(url, type);
    const urlarr = url.replace(/\?/, '/index?');
    console.log("正则表达式", urlarr);
    const urlArr = url.split("?");
    urlArr.splice(1, 0, '/index?');
    console.log("newurl", urlArr)
    if (type == 'navigate') {
      wx.navigateTo({
        url: urlArr.join("")
      });
    }
  },
  onPullDownRefresh() {
    this.setData({
      swiperList: [],
      navList: [],
      floorsList: []
    })
    this.onLoad();
  },
  onPageScroll({ scrollTop }) {
    // console.log("滚动", scrollTop)
    this.setData({
      showtop: scrollTop >= 200 ? true : false
    })
  },
  onReachBottom() {
    console.log("1111")
  }
})

// resolve=(res)=>{
// resolve(result.data.message)  这个括号里面的是实际参数
// }
